
package com.huaweicloud.saaslanding.install.constant;

import com.huaweicloud.saaslanding.basic.constant.UrlConstant;

import jakarta.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @since 2022-03-23
 */
@Component
public class OneAccessConstant {

    /**
     * oneAccess请求头字段（授权）
     */
    public static final String AUTHORIZATION;

    /**
     * 应用Token
     */
    public static final String ACCESS_TOKEN;

    /**
     * 分页页码
     */
    public static final String LIMIT;

    /**
     * 分页偏移量
     */
    public static final String OFFSET;

    /**
     * 应用ID
     */
    public static final String CLIENT_ID;

    /**
     * 应用密钥
     */
    public static final String CLIENT_SECRET;

    /**
     * 授权类型
     */
    public static final String GRANT_TYPE;

    /**
     * 应用凭据（授权类型value）
     */
    public static final String CLIENT_CREDENTIALS;

    /**
     * 组织code
     */
    public static final String ORG_CODE;

    /**
     * 组织Id
     */
    public static final String ORG_ID;

    /**
     * 父级ID
     */
    public static final String PARENT_ID;

    public static final String ACCOUNT_ID;

    /**
     * 名称
     */
    public static final String NAME;

    /**
     * 用户ID
     */
    public static final String USER_ID;

    public static final int LIMIT_MIN;

    public static final int LIMIT_MAX;

    /**
     * oneAccessAPI访问地址
     */
    public String urlPrefix;

    /**
     * 认证凭据Token
     */
    public String tokenUrlPrefix;

    /**
     * oneAccess查询用户(GET)
     */
    public String getUserUrlPrefix;

    /**
     * oneAccess添加用户(POST)
     */
    public String createrUserUrlPrefix;

    /**
     * oneAccess删除用户(DELETE)
     */
    public String deleterUserUrlPrefix;

    /**
     * oneAccess查询组织(GET)
     */
    public String getOrganizationUrl;

    /**
     * oneAccess添加组织(POST)
     */
    public String createOrganizationUrl;

    /**
     * oneAccess删除组织(DELETE)
     */
    public String deleteOrganizationUrlPrefix;

    /**
     * oneAccess给应用赋予应用权限(POST)
     */
    public String addAccountPrefix;

    /**
     * oneAccess删除应用账号
     */
    public String deleteAccountPrefix;

    /**
     * oneAccess查询应用账号
     */
    public String getAccountPrefix;

    /**
     * 应用路径参数（应用）
     */
    public static final String APPLICATIONS;

    /**
     * 应用路径参数（账号）
     */
    public static final String ACCOUNTS;

    /**
     * oneAccess查询组织列表(GET)
     */
    public String getOrganizationListUrl;

    /**
     * oneAccess获取用户列表(GET)
     */
    public String getUserListUrl;

    static {
        LIMIT_MAX = 100;
        LIMIT_MIN = 10;
        AUTHORIZATION = "Authorization";
        ACCESS_TOKEN = "access_token";
        LIMIT = "limit";
        OFFSET = "offset";
        CLIENT_ID = "client_id";
        CLIENT_SECRET = "client_secret";
        GRANT_TYPE = "grant_type";
        CLIENT_CREDENTIALS = "client_credentials";
        ORG_CODE = "org_code";
        ORG_ID = "org_id";
        PARENT_ID = "parent_id";
        USER_ID = "user_id";
        NAME = "name";
        APPLICATIONS = "/applications/";
        ACCOUNTS = "/accounts";
        ACCOUNT_ID = "account_id";
    }

    @Value("${saaslanding-install.idaas.oneaccess.domain:}")
    private String domain;

    @PostConstruct
    private void init() {
        urlPrefix = UrlConstant.HTTPS_PREFIX + domain;
        tokenUrlPrefix = urlPrefix + "/api/v2/tenant/token";
        // 用户
        getUserUrlPrefix = urlPrefix + "/api/v2/tenant/users/";
        createrUserUrlPrefix = urlPrefix + "/api/v2/tenant/users";
        getUserListUrl = urlPrefix + "/api/v2/tenant/users";
        deleterUserUrlPrefix = urlPrefix + "/api/v2/tenant/users/";

        // 组织l
        getOrganizationUrl = urlPrefix + "/api/v2/tenant/organizations/";
        createOrganizationUrl = urlPrefix + "/api/v2/tenant/organizations";
        deleteOrganizationUrlPrefix = urlPrefix + "/api/v2/tenant/organizations/";
        getOrganizationListUrl = urlPrefix + "/api/v2/tenant/organizations";

        // 应用
        addAccountPrefix = urlPrefix + "/api/v2/tenant/users/";
        deleteAccountPrefix = urlPrefix + "/api/v2/tenant/applications/";
        getAccountPrefix = urlPrefix + "/api/v2/tenant/applications/";
    }

}
